from BinaryTree import *

class Solution:
	# @param {TreeNode} root
	# @return {boolean}
	def isSymmetric(self, root):
		if root is None:
			return True
		return self.__isSym(root.left, root. right)

	def __isSym(self, ltree, rtree):
		if bool(ltree) != bool(rtree):
			return False
		if ltree is None:
			return True
		if ltree.val != rtree.val:
			return False
		return (self.__isSym(ltree.left, rtree.right) and 
			self.__isSym(ltree.right, rtree.left))

if __name__ == '__main__':
	t = BinaryTree([1,2,2,3,2,4,3])
	t.display()
	print Solution().isSymmetric(t.tree())